package com.wolf.etl.service.impl;

import com.wolf.etl.model.EtlTransformDefineModel;
import com.wolf.etl.service.IEtlTransformDefineService;
import com.wolf.provider.order.enumerate.QUERY_TYPE;
import com.wolf.provider.order.info.PageBean;
import com.wolf.provider.order.info.PageInfo;
import com.wolf.provider.order.info.ParamBean;
import com.wolf.provider.order.service.impl.BaseServiceImpl;
import com.wolf.util.NumberUtil;
import com.wolf.vo.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by tommy's father on 2017/8/17.
 */
@Service("transform_define_service")
public class EtlTransformDefineServiceImpl extends BaseServiceImpl<Long> implements IEtlTransformDefineService {

    private static Logger logger = LoggerFactory.getLogger(EtlTransformDefineServiceImpl.class);

    private static final String logger_prefix = "wolf-etl#com.wolf.etl.service.impl#EtlTransformDefineServiceImpl";


    @Override
    public List<EtlTransformDefineModel> findByDefineId(Long etl_define_id) {
        StringBuilder sql = new StringBuilder();
        sql.append(" select * from etl_transform_define t where t.etl_define_id=").append(etl_define_id);
        sql.append("  and t.status=1 ");
        Map<String, Object> map = new HashMap<>();
        List<EtlTransformDefineModel> models = findModelListByMap(sql.toString(), map, new EtlTransformDefineModel());
        return models;
    }

    @Override
    public PageResult findByPage(EtlTransformDefineModel model, PageBean pageBean) {

        StringBuilder sql = new StringBuilder();
        sql.append("select * from etl_transform_define t where 1=1 ");

        List<ParamBean> paramBeans = new ArrayList<ParamBean>();

        if (NumberUtil.isNotEmpty(model.getClient_id())) {
            ParamBean paramBean = new ParamBean();
            paramBean.setWhereField("t.client_id");
            paramBean.setField("client_id");
            paramBean.setValue(model.getClient_id());
            paramBean.setType(QUERY_TYPE.EQUAL.getType());
            paramBeans.add(paramBean);
        }

        PageInfo<EtlTransformDefineModel> vos =  findByPageInfo(sql.toString(),paramBeans,model,pageBean);

        PageResult result = new PageResult();
        result.buildResult(vos);
        return result;
    }

}
